<template>
  <div>
    <div class="three">
      <div class="three-from">
        <el-form ref="threeForm" label-width="100px" class="demo-ruleForm">
          <el-form-item class="input" label="设置密码" prop="userPassword">
            <el-input v-model="userPassword" type="password" placeholder="请设置登录密码" />
            <i class="iconfont icon-password pass" />
            <i class="iconfont icon-eye eyes" />
            <div class="box">
              <div v-show="getState" class="error-msg">{{ getPass }}</div>
            </div>
          </el-form-item>
          <el-form-item class="input" label="确认密码" prop="checkPassword">
            <el-input v-model="checkPassword" type="password" placeholder="请确认登录密码" />
            <i class="iconfont icon-password pass" />
            <i class="iconfont icon-close-eyes eyes" />
            <div class="box">
              <div v-show="affirmState" class="error-msg">{{ affirmPass }}</div>
            </div>
          </el-form-item>
        </el-form>
      </div>
      <div class="content-item">
        <button class="last-step distance" @click="last">上一步</button>
        <button class="btn distance" @click="next">下一步</button>
      </div>
    </div>
  </div>
</template>
<script>
import { passwordReg } from '@/js/regex'
import { resetPassword } from '@/api/reset-password'
export default {
  name: 'ThirdRestPWD',
  props: {
    passwordForm: {
      required: true,
      type: Object
    }
  },
  data() {
    return {
      userPassword: undefined,
      checkPassword: undefined,
      getPass: '',
      affirmPass: '',
      getState: false,
      affirmState: false
    }
  },
  methods: {
    last() {
      this.$emit('last')
    },
    next() {
      this.$emit('next')
      if (!this.userPassword) {
        this.getPass = '请先填写密码'
        this.getState = true
        return false
      }
      if (!passwordReg.test(this.userPassword)) {
        this.getPass = '密码格式不正确：6-18位字符，只能并且必须包含字母和数字'
        this.getState = true
        return false
      }
      if (!this.checkPassword) {
        this.affirmPass = '请先确认密码'
        this.getState = false
        this.affirmState = true
        return false
      }
      if (this.userPassword !== this.checkPassword) {
        this.affirmPass = '两次密码不一致'
        this.getState = false
        this.affirmState = true
        return false
      }
      const { userName, uuid } = this.passwordForm
      const { userPassword } = this
      const headers = { userName, userPassword }
      resetPassword(headers, uuid).then(res => {
        if (res.data) {
          this.$message('重置密码成功')
          this.$emit('next')
        } else {
          this.$message(res.message)
        }
      // }).catch(error => {
      //   this.$message(error.data)
      })
    }
  }
}
</script>
<style scoped lang="scss">
  .password{
    padding-top: 127px;
    padding-bottom: 87px;
    background: #F5F5F5;
    .password-content{
      background: #FFFFFF;
      .contents{
        height: 600px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        .step{
          margin-left: 470px;
          width: 490px;
        }
        .three{
          .three-from{
            margin-top: 47px;
            margin-left: 340px;
          }
          .input{
            position: relative;
            margin-bottom: 0px;
            .box{
              height: 20px;
              line-height: 20px;
              .error-msg{
                text-align: left;
                padding-left: 30px;
                color: #f56c6c;
              }
            }
          }
          .pass{
            position: absolute;
            left: 50px;
            font-size: 24px;
            top: -1px;
          }
          .eyes{
            position: absolute;
            left: 380px;
            font-size: 24px;
            top: -1px;
            color: #C7C7CC;
            cursor: pointer;
          }
        }
        .content-item{
          margin-top: 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
            .distance{
              margin-left: 140px;
            }
            .last-step{
              background: #ffffff;
              border: 1px solid #C7C7CC;
              width: 400px;
              height: 42px;
              line-height: 42px;
              text-align: center;
              color: #A7A7AA;
              cursor: pointer;
              border-radius: 3px;
              margin-left: 140px;
              margin-bottom: 16px;
              font-size: 18px;
            }
          }
        .btn{
            background: #FF3B30;
            width: 400px;
            height: 42px;
            line-height: 42px;
            text-align: center;
            color: #FFFFFF;
            cursor: pointer;
            border-radius: 3px;
            margin-left: 130px;
            font-size: 18px;
          }
      }
    }
    /deep/ .three-from{
      .el-form-item{
        margin-bottom: 0px !important;
      }
    }
    /deep/ .three-from{
      .el-form-item{
        margin-bottom: 0px !important;
      }
    }
    /deep/.contents{
      .el-form-item__error{
        margin-left: 30px;
      }
    }
    /deep/ .contents{
      .el-input{
        width: 400px;
        height: 42px;
      }
      .el-form-item__label{
        width: 130px !important;
      }
    }
    /deep/ .steps {
      .el-steps{
        position: absolute;
        width: 1000px;
        top:40px;
        right: -340px;
      }
    }
    /deep/ .one{
      .el-input__inner{
        text-indent: 40px;
      }
    }
    /deep/ .three-from{
      .el-input__inner{
        text-indent: 40px;
      }
    }
    /deep/ .from{
      .el-input__inner{
        text-indent: 40px;
      }
    }
    /deep/ .content-item{
      .el-input{
        width: 280px;
      }
    }
  }
</style>
